import time


def clocked(top=3):
    result = []

    def clock(func):
        def inner(*args, **kwargs):
            start = time.time()
            res = func(*args, **kwargs)
            end = time.time()
            cost = end - start
            result.append((cost, args, kwargs))
            result.sort(key=lambda x: x[0])

            # 打印耗时最短的前top样例
            print(f'当前耗时：{cost}')
            print(f'执行前{top}的如下：')
            for item in result[:top]:
                print(f'耗时：{item[0]} 参数配置：{item[1]}')

            return res

        return inner

    return clock
